﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;

namespace Infrastructure.Interfaces
{
    public interface IRepository<T> where T : class
    {
        event EventHandler<ResultOperationEventArgs> NotifyResultOperation;

        void GetAll(Action<IEnumerable<T>> callback);
        void GetByFilter(Expression<Func<T, bool>> filter, Action<IEnumerable<T>> callback);
        void GetById(int id, Action<T> callback);
        void GetFirst(Expression<Func<T, bool>> filter, Action<T> callback);

        void Delete(T entity);
        void Add(T entity);
        void Attach(T entity);
        void SaveChanges();
    }

    public class ResultOperationEventArgs : EventArgs
    {
        public Exception Error { get; set; }
        //
        // Summary:
        //     Gets a value indicating whether the operation has failed. If true, inspect
        //     the Error property for details.
        public bool HasError { get; set; }
        //
        // Summary:
        //     Gets a value indicating whether this operation has been canceled.
        //
        // Remarks:
        //     Note that successful cancellation of this operation does not guarantee state
        //     changes were prevented from happening on the server.
        public bool IsCanceled { get; set; }
        //
        // Summary:
        //     Gets a value indicating whether this operation has completed.
        public bool IsComplete { get; set; }
        //
        // Summary:
        //     Gets a value indicating whether the operation error has been marked as handled
        //     by calling System.ServiceModel.DomainServices.Client.OperationBase.MarkErrorAsHandled().
        public bool IsErrorHandled { get; set; }
    }
}
